package org.cancan.demo.opencv;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;

/**
 * 摄像头
 */
public class CameraCapture {

    private VideoCapture camera;

    private Mat frame;

    public CameraCapture(){
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        camera = new VideoCapture(0);
        frame = new Mat();
    }

    public Mat captureFrame(){
        if(camera.isOpened()){
            camera.read(frame);
        }
        return frame;
    }

    public void release(){
        if(camera.isOpened()){
            camera.release();
        }
    }

}
